/**
 * 验证规则选项接口
 * @description 验证规则选项接口
 */
import * as Validators from './validators/index';

/**
 * 函数类型的验证规则
 * 
 * @type {function} - 接收字段值，返回验证结果，true表示验证通过，字符串表示错误信息
 */
export type ValidationFunction<T = any> = (value: T) => true | string;

/**
 * 验证规则类型枚举
 */
export type ValidationType =
  | 'required'
  | 'number'
  | 'email'
  | 'phone'
  | 'min'
  | 'max'
  | 'minMax'
  | 'pattern'
  | 'custom'
  | 'url'
  | 'idCard'
  | 'dateTime'
  | 'ip'
  | 'range'
  | 'charType'
  | 'passwordStrength'
  | 'file'
  | 'list'
  | string;

/**
 * 验证选项联合类型 - 支持所有验证选项类型
 */
export type ValidationOptions =
  | Validators.RequiredValidationOptions
  | Validators.NumberValidationOptions
  | Validators.EmailValidationOptions
  | Validators.PatternValidationOptions
  | Validators.CustomValidationOptions
  | Validators.PhoneValidationOptions
  | Validators.UrlValidationOptions
  | Validators.IdCardValidationOptions
  | Validators.DateTimeValidationOptions
  | Validators.IpValidationOptions
  | Validators.RangeValidationOptions
  | Validators.MinMaxValidationOptions
  | Validators.NumberValidationOptions
  | Validators.CharTypeValidationOptions
  | Validators.PasswordStrengthValidationOptions
  | Validators.FileValidationOptions
  | Validators.ListValidationOptions;

/**
 * 对象类型的验证规则接口
 * @property {ValidationType} type - 验证类型，如'required'、'number'、'email'等
 * @property {string} [message] - 自定义错误信息
 * @property {ValidationOptions} [options] - 验证选项
 */
export interface ValidationRuleObject {
  /**
   * 验证类型，用于标识执行何种验证
   * 
   * @type {ValidationType}
   */
  type: ValidationType;

  /**
   * 自定义错误信息
   * 
   * @type {string}
   */
  message?: string;

  /**
   * 验证选项，根据type的不同而有所不同
   * 
   * @type {ValidationOptions}
   */
  options?: ValidationOptions;
}

/**
 * 单个验证规则类型
 * 
 * @type {ValidationFunction | ValidationRuleObject}
 */
export type ValidationRule<T = any> = ValidationFunction<T> | ValidationRuleObject;

/**
 * 验证结果接口
 * @property {boolean} valid - 验证是否通过
 * @property {string} [message] - 验证失败时的错误消息
 */
export interface ValidationResult {
  valid: boolean;
  message?: string;
}